
//$("a[name='collect']").prev().val()

/* function collect(aa){

     var id = $(aa).prev().val();
     alert(id);

 }*/
$(function () {
    $(".car_tab .addCollect").live("click",function () {
        var id = $(this).parent().find(".shanchu").val();
        if(localStorage.length == 0){
            if(confirm("请先登录")){
                window.location.href = "Login.html";
            }
        }else if(localStorage.length>0){
            var userName = localStorage.getItem("user");
            $.ajax({
                url : "easybuy/product/collect",
                dataType : "json",
                data : {"id" : id,"userName":userName},
                type : "get",
                success : function (data) {
                    if(data.result =="success"){
                        alert("收藏成功");
                    }else if(data.exist=="exist"){
                        alert("您已收藏过该商品！");
                    }
                },
                error : function (XMLHttpRequest, textStatus, errorThrown) {
                    alert("出现错误");
                    console.log(XMLHttpRequest.status);
                    console.log(XMLHttpRequest.readyState);
                    console.log(textStatus);
                }
            });

        }

    });
});

